package AOP.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author zyl
 * @Description
 * @since 2024/1/22 15:10
 */
@Component
@Aspect
public class MyAspect {

    @Pointcut("execution(* AOP.aop.UserService.printUser(..))")
    public void pointCut(){
    }

    @Before("pointCut()")
    public void before(){
        System.out.println("*****Before*****");
    }

    @AfterReturning("pointCut()")
    public void after(){
        System.out.println("*****after*****");
    }
    @AfterThrowing("pointCut()")
    public void afterThrowing(){
        System.out.println("*****afterThrowing*****");
    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint joinPoint){
        System.out.println("*****Around Before*****");
        try {
            //回调切点的方法 不写这个的话就不会调切点的方法
            joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("*****Around after*****");
    }
}

